package com.bingxue.edu.framework.mybatis.base;

import com.mybatisflex.core.mybatis.MappedStatementTypes;
import com.mybatisflex.core.util.MapperUtil;

import java.io.Serializable;

/**
 * Mapper 基类
 *
 * @param <T> 实体类
 * @author panbo
 * @since 2024/6/28
 */
@SuppressWarnings("unchecked")
public interface BaseMapper<T> extends com.mybatisflex.core.BaseMapper<T> {

    default <R> R selectOneByIdAs(Serializable id, Class<R> asType) {
        Object result;
        try {
            MappedStatementTypes.setCurrentType(asType);
            result = this.selectOneById(id);
        } finally {
            MappedStatementTypes.clear();
        }
        return (R) result;
    }
}
